<script type="text/javascript" language="javascript" charset="utf-8">
$(".header-con li a").removeClass("open-menu");
$(".header-con li #configuration").addClass("open-menu");
</script>
<div class="boxed clearfix">
  <div class="common-tit">
    <h2>课程设置</h2>
    <span>公司设置 > 课程设置</span>
  </div>
  <div class="ad-box">
    <div class="account-infor">
      <%= render partial: "company_configuration_nav" %>
      <h3>
        <em>*</em>
        <span>教室</span>
      </h3>
      <div class="comp-setbox">
        <div class="comp-set">
          <% @course_rooms.each do |room| %>
            <div class="com-wdr clearfix">
              <ul class="com-adcon">
                <li>
                  <span>所属分店:</span>
                  <em><%= room.studio.try :name %></em>
                </li>
                <li>
                  <span>教室名称:</span>
                  <em><%= room.room_name %></em>
                </li>
                <li>
                  <span>教室位置:</span>
                  <em><%= room.location %></em>
                </li>
                <li>
                  <span>人数上限:</span>
                  <em><%= room.max_contain %></em>
                </li>
              </ul>
              <div>
                <%= link_to '删除','javascript:void(0)',
                  onclick: "ajax_function('/admin/company_configurations/destroy_configuration', 'course_room', 'CourseRoomConfiguration', #{room.id})",
                  id: "delete_course_room#{room.id}", class: "comm-del" %>
            </div>
            </div>
          <% end %>


          <%= form_for(@course_room, url: create_course_room_admin_company_configurations_path, html: { multipart: true}) do |f| %>
            <div class="com-adr clearfix">
              <ul class="com-adcon">
                <li>
                  <span>所属分店:</span>
                  <%= f.text_field :studio_id, required: true, id: "courseCon" %>
                  <div class="list-box">
                    <div class="downbtn">
                      <span data_id="all">请选择分店</span>
                      <em></em>
                    </div>
                    <ul class="dropdown-menu">
                      <% @current_studios.each do |studio| %>
                        <li data_id="<%= studio.id %>"><%= studio.name %></li>
                      <%end%>
                    </ul>
                  </div>
                </li>
                <li>
                  <span>教室名称:</span>
                  <%= f.text_field :room_name, required: true %>
                </li>
                <li>
                  <span>教室位置:</span>
                  <%= f.text_field :location, required: true %>
                </li>
                <li>
                  <span>人数上限:</span>
                  <%= f.number_field :max_contain, required: true %>
                </li>
              </ul>
              <div class="comm-add">
                <span><%= f.submit "添加", class: "add-button"%></span>
                <div class="com-addinfo">至少添加一条教室信息</div>
              </div>
            </div>
            <%# f.select :studio_id, options_for_select(@current_studios.map{|u| [u.name, u.id]}), prompt: "所属分店" %>
          <% end %>
        </div>
      </div>
      <h3>
        <em>*</em>
        <span>私教设置</span>
      </h3>

      <%= form_for(@private_education, url: update_private_education_admin_company_configurations_path, method: :post, html: { multipart: true}) do |f| %>
        <div class="comp-dset clearfix">
          <span>私教时长:</span>
          <%= f.text_field :duration, required: true, id: "priEdu" %>
          <em>小时</em>
          <%= submit_tag "保存", class: "set-combtn" %>
        </div>
      <% end %>

    </div>
    <!-- <div class="com-sbtn">保存</div> -->
  </div>
</div>

<script src="/assets/js/common-list.js"></script>
<script>
// $(".com-sbtn").on("click", function() {
//   var canSub = true;
//   if ($(".comp-set .com-wdr").length < 1) {
//     canSub = false;
//     // 出提示  至少一条
//     $(".com-addinfo").css({
//       "display" : "block"
//     });
//   } else {
//     $(".com-addinfo").css({
//       "display" : "none"
//     });
//   }
//   if ($("#priEdu").val() == "") {
//     $("#priEdu").css({
//       "border" : "1px solid #ff5a60"
//     });
//     canSub = false;
//     // 出提示  至少一条
//   } else {
//     $("#priEdu").css({
//       "border" : "1px solid #9ea0b7"
//     });
//   }
//   if (canSub) {
//     console.log("通过验证");
//   };
// })
  $(".com-adcon .list-box li").on("click", function() {
    $("#courseCon").val($(this).attr("data_id"));
  })
</script>

<script>
//删除舞蹈教室
ajax_function = function (url, type, model_name, value){
  var id="#delete_" +type +value
    if (confirm("确认删除吗？")){
      $.ajax({
        url: url,
        type:'DELETE',
        data: {
          model_name: model_name,
          value: value,
        },
        success: function(data){
          $(id).parent().parent().remove();
        },
        error:function(){
          alert("出错");
        }
      });
    }
}
</script>
